<?php
declare(strict_types=1);

namespace app\api\controller;


use app\api\validate\User;
use app\BaseController;
use think\exception\ValidateException;
use app\common\business\Sms as SmsBus;

class Sms extends BaseController
{
    public function code() :object{
        $phoneNumber = input('param.phone_number', '', 'trim');
        $data = [
            'phone_number' => $phoneNumber,
        ];
        // 手机号码校验
        try {
            validate(User::class)->scene("send_code")->check($data);
        }catch(ValidateException $e){
            return show(config("status.error"), $e->getError());
        }
        // 调用business
        if(SmsBus::sendCode($phoneNumber, 4, "ali")){//可以按比例分给不同的短信运营商流量
            return show(config("status.success"), "发送验证码成功");
        }
        return show(config("status.error"), "发送验证码失败");
    }
}
